package com.maegul.data.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.maegul.data.dao.AbstractDAO;
import com.maegul.data.entities.MediaItem;

@Repository(value = "mediaItemDao")
public class MediaItemDaoImpl extends AbstractDAO<MediaItem> implements MediaItemDao {

	@PersistenceContext
	private EntityManager em;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.maegul.data.dao.DAO#getEntityManager()
	 */
	public EntityManager getEntityManager() {
		return em;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.maegul.data.dao.DAO#getClazz()
	 */
	public Class<MediaItem> getClazz() {
		return MediaItem.class;
	}

	/* (non-Javadoc)
	 * @see com.maegul.data.dao.impl.MediaItemDao#findByName(java.lang.String)
	 */
	public MediaItem findByName(String name) {
		Query q = getEntityManager().createQuery("select u from " + getClazz() + " where u.name = :name");
		q.setParameter("name", name);
		
		return (MediaItem) q.getSingleResult();
	}

	/* (non-Javadoc)
	 * @see com.maegul.data.dao.impl.MediaItemDao#findByType(java.lang.String)
	 */
	public List<MediaItem> findByType(String type) {
		// TODO Auto-generated method stub
		return null;
	}
}
